<template>
  <div>
    <el-dialog
      :title="form.id?'编辑区域':'新增区域'"
      width="60%"
      :visible.sync="visible"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="区域名称" prop="name">
          <el-input
            v-model="form.name"
            type="text"
            placeholder="请输入内容"
            maxlength="10"
            show-word-limit
          />
        </el-form-item>

        <el-form-item label="区域方案" prop="remark" style="width:84%">
          <div style="margin: 20px 0;" />
          <el-input
            v-model="form.remark"
            type="textarea"
            placeholder="请输入内容"
            maxlength="30"
            show-word-limit
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="visible=false">取 消</el-button>
        <el-button type="primary" @click="sure">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { putSearch, addRegion } from '@/api/regional'
export default {
  name: 'DikedeUpdate',

  data() {
    return {
      visible: false,
      form: {},
      rules: {
        policyName: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        discount: [
          { required: true, message: '请输入', trigger: 'blur' }
        ]
      }
    }
  },

  mounted() {

  },
  methods: {
    async sure() {
      try {
        await this.$refs.form.validate()
        this.form.id ? await putSearch(this.form) : await addRegion(this.form)
        this.$message.success(`${this.form.id ? '编辑' : '新增'}成功`)
        this.$refs.form.resetFields()
        this.visible = false
        this.$parent.getSearch()
      } catch (e) {
        console.log(e)
      }
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
